<%@page import="com.railway.msg.model.*"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<html>

	<head>

		<link rel="stylesheet" type="text/css" href="${ctx}/css/default.css" />

		<script type="text/javascript"
			src="${ctx}/scripts/jquery-1.4.2.min.js"></script>
		<script type="text/javascript"
			src="${ctx}/scripts/jquery.easyui.min.js"></script>
		<script type="text/javascript"
			src="${ctx}/scripts/locale/easyui-lang-zh_CN.js"></script>
		<script type="text/javascript"
			src="${ctx}/scripts/jquery-1.4.4.min.js"></script>
		<script type="text/javascript" src="${ctx}/scripts/easyTooltip.js"></script>
		<style>
body {
	margin: 0;
	padding: 40px;
	background: #fff;
	font: 80% Arial, Helvetica, sans-serif;
	color: #555;
	line-height: 180%;
}

h1 {
	font-size: 180%;
	font-weight: normal;
}

h2 {
	font-size: 160%;
	font-weight: normal;
}

h3 {
	font-size: 140%;
	font-weight: normal;
}

img {
	border: none;
}

pre {
	display: block;
	font: 12px "Courier New", Courier, monospace;
	padding: 10px;
	border: 1px solid #bae2f0;
	background: #e3f4f9;
	margin: .5em 0;
}

/* Easy Tooltip */
#easyTooltip {
	padding: 5px 10px;
	border: 1px solid #195fa4;
	background: #195fa4 url(bg.gif) repeat-x;
	color: #fff;
}

#easyTooltip2 {
	padding: 5px 10px;
	border: 1px solid #5e5e5e;
	background: #5e5e5e url(bg2.gif) repeat-x;
	color: #fff;
	width: 160px;
}

#easyTooltip2 h4,#easyTooltip2 p {
	margin: .25em 0;
}
/* // Easy Tooltip */
</style>

		<script type="text/javascript"> 
	
        function getRnValue(){
            var tempid= '' ;
         	var tempname = '';
         	$("input[name^='chk']:checkbox:checked").each(function(){     
	    	   tempid += $(this).val() +",";
	    	   tempname +=$(this).attr("title") +",";
	       }) ;

            window.returnValue = new Array(tempid,tempname);
            window.close();  
        }

		//通过部门选择人员
		function selectusersbydept(obj){
		        if(obj.checked == true){
   		    	$("input[name^='"+obj.name+"']").attr("checked","true");
   		    	} else{   		 		    	
   		    		$("input[name^='"+obj.name+"']").attr("checked","");
   		    	}
		}
	    $(document).ready(function() {  
	     //全选 
		$("#btn1").click(function(){ 

		 $("input[name^='chk']").attr("checked","true"); 
	    }) 
       //取消全选 
	    $("#btn2").click(function(){ 
		 $("input[name^='chk']").removeAttr("checked"); 
	    })   
	    $("a").easyTooltip();    	
	    var zNodes ;  
	    $.get("${ctx}/system/SysUser/getUserDeptList.do", {	            
          Action:"get",Name:"user01"}, function (data, textStatus){      
            		 
             zNodes  = eval(data); 
             for(var k = 0 ; k < zNodes.length;k++){
                     var nodes = zNodes[k];    
                     var us = nodes.users;
        
                     var onerow = "<tr><td><input type='checkbox' onclick = 'javascript:selectusersbydept(this)' name='chk"+nodes.did+"' value=''/><img src='${ctx}/css/dept.gif'/>"+nodes.dn+"</td><td>";
                    
                     for(var kk =0 ; kk < us.length; kk++){   
                           
                        var status = us[kk].ustatus;
                        onerow += "<label style='width:90px;height:30px;'><input type='checkbox' title='"+us[kk].un+"' name='chk"+nodes.did+"_"+us[kk].uid+"' value='"+us[kk].uid+"'/><img src='${ctx}/css/user.gif'/><a href='#' id='"+us[kk].uid+"'><font color='"+status+"'>"+us[kk].un+"</font></a>&nbsp;&nbsp;</label>" ;
           		        
           		        //if((kk +1) % 8 ==0){
                         //  onerow += "<br>";
                    //    }
                     	}
                      onerow += "</td></tr>";
                      $("#chktable").append(onerow);      
                                     
             }                 
             for(var k = 0 ; k < zNodes.length;k++){
             
                     var nodes = zNodes[k];    
                     var us = nodes.users;
        
                     for(var kk =0 ; kk < us.length; kk++){  
                        var status = us[kk].ustatus;
                   		$("a#"+us[kk].uid+"").easyTooltip({
						tooltipId: "easyTooltip2",
						content: ''+us[kk].uinfo
						});                        
                     }                     
                                   
             } 
             
             initcheckedusers();
			});	
       
	}); 
	
     function initcheckedusers_old(){
             var obj = window.dialogArguments;
	         var authvalue ;

	         if(form1.userTypes.value == 'C'){
	      
	      		    authvalue = obj.all.form1.checkerid.value ;
	      	
	      	
            }else if(form1.userTypes.value =='M'){
                    authvalue = obj.all.form1.maintainerid.value; 	
            
            }else if(form1.userTypes.value = 'V'){
              
                    authvalue = obj.all.form1.visitorid.value;
     
            }
            if(authvalue != undefined & authvalue != ''){	      		    
	      		   var temp =   authvalue.split(",");
	      		   $("input[name^='chk']").each(function(){	      		      
	        		     for(var j =0 ; j < temp.length; j++){  
	      		            if(temp[j] == ''){continue;}
	      		            if( $(this).attr("value") == temp[j]){
	      		                $(this).attr("checked","true"); 
	      		            }
	      		         }
	                }) ;
	      		  
	        }
     
     
     }
  function initcheckedusers(){
      		 var hashMap = {   
    	 		set : function(key,value){this[key] = value},   
    	 		get : function(key){return this[key]},   
    	 		contains : function(key){return this.get(key) == null?false:true},   
    			remove : function(key){delete this[key]}   
 	         }  
             var obj = window.dialogArguments;
	         var authvalue ;

	         if(form1.userTypes.value == 'C'){	      
	      		    authvalue = obj.all.form1.checkerid.value ;      	
             }else if(form1.userTypes.value =='M'){
                    authvalue = obj.all.form1.maintainerid.value; 	
            
             }else if(form1.userTypes.value = 'V'){              
                    authvalue = obj.all.form1.visitorid.value;     
             }
             if(authvalue != undefined & authvalue != ''){
	      		    
	      		   var temp = authvalue.split(",");
	      	
	               for(var j =0 ; j < temp.length; j++){  
	                        if(temp[j] == ''){continue;}
	      		            hashMap.set(temp[j],"");
	      		   }	      		 
	      	       $("input[name^='chk']").each(function(){		      		       		 
	        		     if(hashMap.contains($(this).attr("value"))){
	        		     	 $(this).attr("checked","true"); 
	        		      }        	      		         
	               });	    
	                                  
	               for(var j =0 ; j < temp.length; j++){  	            
	                        if(temp[j] == ''){continue;}
	      		            hashMap.remove(temp[j],"");
	      		   }
	      		   		  
	        }     
     }

	</script>
	<title></title>
	</head>
	<body>

		<div>
			<p>
				<label class="someClass" title="选择相关的人员进行消息发送">
					选择人员(鼠标滑动到人名上查看详细信息)
					<font color='blue'>在线</font>/离线
				</label>

				<input type="button" id="btn1" value="全选" />
				<input type="button" id="btn2" value="取消全选" />
				<input type="button" value="确定" onclick="javascript:getRnValue();" />

			</p>
			<div
				style="line-height:50px; overflow-y: auto; overflow-x: auto; width: 100%; height: 250px;">

				<table id="chktable" style="width: 100%; height: 250px;line-height:110px;">
					<tr >
						<td width="150">
							<strong>部门 </strong>
						</td>
						<td>
							<strong>人员 </strong>
						</td>
					</tr>
				</table>
			</div>
			<!--div style="overflow-x:auto;overflow-y:auto; overflow-x:auto; width:600px; height:300px;"-->
			<div>
				<form id="form1">
                    <input type="hidden" name = "userTypes" value="<%=request.getParameter("userTypes") %>"/>

					<table class="formTable">

						<input type="hidden" id="id" name="id" value="" />

						<input type="hidden" id="targetids" name="targetids" value="" />


					</table>
				</form>

			</div>
	</body>

</html>

